﻿using System;
using System.Collections.Generic;
using Tools.Domain.Specifications.Constraints;
using Webshop20.Domain.Orders.Factories.Contracts;
using Webshop20.Domain.Orders.Core;
using Webshop20.Domain.Orders.Enumerations;
using Webshop20.Domain.Customers.Services.DataTransferObjects;
using Webshop20.Domain.Shared.Payment.Core;
using Webshop20.Model.Orders.Specifications;

namespace Webshop20.Domain.Orders.Factories.Implementation
{
    public class OrderFactory : IOrderFactory
    {
        #region IOrderFactory Members

        public Order CreateInstance(CustomerInformationDTO customerInformations, IList<Position> positions, IPayment paymentMethod, DateTime orderDate)
        {
            return new Order(
                                0,
                                customerInformations.Id,
                                OrderState.Processing,
                                orderDate,
                                CreateOrderAdressFrom(customerInformations),
                                CreateOrderAdressFrom(customerInformations),
                                paymentMethod,
                                positions, 
                                customerInformations.EMail, 
                                false,
                                new OrderConstraintSet(new ExecuteAlways())
                             );

        }

        #endregion

        private OrderAdress CreateOrderAdressFrom(CustomerInformationDTO customerInformations)
        {
            return new OrderAdress(
                                                    customerInformations.FirstName,
                                                    customerInformations.LastName,
                                                    customerInformations.Street,
                                                    customerInformations.PostalCode,
                                                    customerInformations.City,
                                                    customerInformations.Country
                                                );
        }


    }
}